<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>js中的String对象</title>
</head>
<body>
    <script>
        // 创建
        var s1 = new String("hello");
        var s2 = "world";
        // 基本的属性和方法
        // 输出字符串的长度
        console.log(s2.length);
        // 在字符串中查找字符
        console.log(s2.indexOf("o"));
        console.log(s2.lastIndexOf("o"));
        // 返回字符的位置
        console.log(s2.charAt(2));
        console.log(s2.charCodeAt(2));
        // 截取字符串
        console.log(s2.slice(1, 3));
        console.log(s2.substring(1, 3));
        console.log(s2.substr(1, 3));
        // 替换
        console.log(s2.replace("o", "a"));
        // 分割
        console.log(s2.split("o"));
        // 拼接
        console.log(s2.concat("!", "!", "!"));

    </script>
</body>
</html>